<?php

/**
 * This is the model class for table "alquiler".
 *
 * The followings are the available columns in table 'alquiler':
 * @property integer $alquiler_id
 * @property string $fecha
 * @property string $hora_comienzo
 * @property string $hora_fin
 * @property integer $estado
 * @property integer $clientes_id
 * @property integer $canchas_id
 * @property string $fecha_hora
 *
 * The followings are the available model relations:
 * @property Clientes $clientes
 * @property Canchas $canchas
 * @property Estados $estado0
 */
class Alquiler extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Alquiler the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'alquiler';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('fecha, hora_comienzo, hora_fin, estado, clientes_id, canchas_id', 'required'),
			array('estado, clientes_id, canchas_id', 'numerical', 'integerOnly'=>true),
			array('fecha_hora', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('alquiler_id, fecha, hora_comienzo, hora_fin, estado, clientes_id, canchas_id, fecha_hora', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'clientes' => array(self::BELONGS_TO, 'Clientes', 'clientes_id'),
			'canchas' => array(self::BELONGS_TO, 'Canchas', 'canchas_id'),
			'estado0' => array(self::BELONGS_TO, 'Estados', 'estado'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'alquiler_id' => 'Alquiler',
			'fecha' => 'Fecha',
			'hora_comienzo' => 'Hora Comienzo',
			'hora_fin' => 'Hora Fin',
			'estado' => 'Estado',
			'clientes_id' => 'Clientes',
			'canchas_id' => 'Canchas',
			'fecha_hora' => 'Fecha Hora',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('alquiler_id',$this->alquiler_id);
		$criteria->compare('fecha',$this->fecha,true);
		$criteria->compare('hora_comienzo',$this->hora_comienzo,true);
		$criteria->compare('hora_fin',$this->hora_fin,true);
		$criteria->compare('estado',$this->estado);
		$criteria->compare('clientes_id',$this->clientes_id);
		$criteria->compare('canchas_id',$this->canchas_id);
		$criteria->compare('fecha_hora',$this->fecha_hora,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}